package com.enjoyor.soa.traffic.frame.support.builder;

import java.util.HashMap;
import java.util.Map;

public class MapBuilder<K, V> {

    private Map<K, V> mapParam;

    /**
     * 默认构造函数
     */
    public MapBuilder() {
        mapParam = new HashMap<K, V>();
    }

    /**
     * 有参构造函数
     * 
     * @param mapParam
     */
    public MapBuilder(Map<K, V> mapParam) {
        this.mapParam = mapParam;
    }

    /**
     * put方法，返回MapParamBuilder构建器
     * 
     * @param key
     * @param value
     * @return
     */
    public MapBuilder<K, V> put(K key, V value) {
        mapParam.put(key, value);
        return this;
    }

    /**
     * 删除Key
     * 
     * @param key
     * @return
     */
    public MapBuilder<K, V> remove(K key) {
        mapParam.remove(key);
        return this;
    }

    /**
     * 返回构建好的map参数
     * 
     * @return
     */
    public Map<K, V> build() {
        return mapParam;
    }

    public static void main(String[] args) {
        Map<String, String> map = new MapBuilder<String, String>().put("key1", "value1").put("key2", "value2").build();

        System.out.println("初始化参数输出");
        for (String key : map.keySet()) {
            System.out.println("key=" + key + ",value=" + map.get(key));
        }
     
    }

}
